<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Jamin
  Date: 2019/1/24
  Time: 09:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css">
    <script src="../../My97DatePicker/WdatePicker.js"></script>
    <script src="../../js/jquery.min.3.1.0.js"></script>
    <style>
        .account{
            width: 191px;
        }
        .tops{
            width: auto;
            height: 59px;
            background:white;
        }
        body{
            background: white;
        }
    </style>
</head>
<body>
<div class="tops"></div>

<!--优惠券信息修改表单-->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>优惠券信息修改</legend>
</fieldset>
<form id="a" class="layui-form" action="" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-inline">
            <input type="text"  name="c_id" required lay-verify="c_id" autocomplete="off" class="layui-input" readonly="readonly" value="${c.cID}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">优惠券描述</label>
        <div class="layui-input-inline">
            <input type="text" name="c_description" required lay-verify="c_description" autocomplete="off" class="layui-input" value="${c.cDescription}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">满足条件</label>
        <div class="layui-input-inline">
            <input type="text" name="c_term" required lay-verify="c_term" autocomplete="off" class="layui-input" value="${c.cTerm}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">优惠价格</label>
        <div class="layui-input-inline">
            <input type="text" name="c_vipprice"  lay-verify="c_vipprice" autocomplete="off" class="layui-input" value="${c.cVipPrice}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">截止时间</label>
        <div class="layui-input-inline">
            <input type="text" name="c_deadline" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})" lay-verify="c_deadline" autocomplete="off" class="layui-input" value="${c.cDeadline}">
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="modify">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="../../layuiadmin/layui/layui.js"></script>
<script>

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit

        form.verify({
            c_description: function(value){
                if(value.length==0){
                    return '优惠券描述不得为空';
                }
            }
            , c_term:
                [/^[1-9]\d*|0$/
            ,'使用条件输入不正确'
             ]

            ,c_vipprice:[/^[1-9]\d*|0$/
                ,'优惠金额输入不正确']

        });
        /**
         * 会员信息的修改
         * 监听提交
         */
        form.on('submit(modify)', function(data){
            var index = parent.layer.getFrameIndex(window.name);

            $.ajax({
                url:"/ModifyServelt",   //请求路径
                datatype:"json",//返回的格式
                data:$('#a').serialize(), //参数
                type:"POST", //什么请求
                success:function (data) { //请求成功以后
                    //AJAX成功以后返回的
                    var obj = eval('(' + data + ')');
            if (obj.update){
                alert("修改成功");
                window.close();
            } else{
                alert("修改失败");
                window.location.href="ModifyCoupon.jsp";
            }
                }
            });
            return false;
        });

    });
</script>
</body>
</html>